<#assign module="marketing"/>

<@override name="header">
</@override>
<@override name="body">
    <div class="row">
        <div class="col-xs-12">

        </div>
    </div>
    <div class="row margin-top">
        <div class="col-xs-12">
            <div class="table-responsive">

                <div class="panel panel-default">
                    <div class="panel-heading">
                        ${couponRule.title}&nbsp;&nbsp;有效期：${couponRule.start?string('yyyy/MM/dd')}&nbsp;-&nbsp;<#if couponRule.end??>${couponRule.end?string('yyyy/MM/dd')}<#else>不限</#if>
                        &nbsp;&nbsp;
                        <#if couponRule.timeStatus==0>
                            （未开始）
                        <#elseif couponRule.timeStatus==1>
                            （使用中）
                        <#elseif couponRule.timeStatus==2>
                            （已过期）
                        </#if>
                    </div>
                </div>

                <div class="panel panel-default margin-top">
                    <div class="panel-heading">
                        生成优惠劵
                    </div>
                    <div class="panel-body">
                        <form id="submit_form" action="${ctx}/couponrule/mass" class="form-horizontal" method="post">
                            <input type="hidden" name="couponRuleId" value="${couponRule.id}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><em>*</em>数量：</label>
                                <div class="col-sm-3">
                                    <input class="form-control" id="amount" name="amount" type="number" value="" required placeholder="输入需生成优惠劵的数量"/>
                                    <span class="help-block">一次性最多生成300张优惠劵。</span>
                                </div>
                            </div>

                            <div class="form-group" style="margin-left:10px;">
                                <label class="col-sm-3 control-label"></label>
                                <input id="submit_button" type="button" class="btn btn-primary" value="生成">
                                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/couponrule/list';" value="返回">
                            </div>
                        </form>
                    </div>
                </div>

            </div>
        </div>
    </div>
</@override>
<@override name="footer">
    <script type="text/javascript">
        $(document).ready(function(){

            $("#submit_button").click(function(){
                var amount=$("#amount").val();
                if(amount.length>0){
                    var reg=/^(\d+)$/;
                    if(!reg.test(amount)){
                        $.scojs_message('无效的数量！', $.scojs_message.TYPE_ERROR);
                        return false;
                    }

                    if(amount>300){
                        $.scojs_message('一次最多生成300张优惠劵！', $.scojs_message.TYPE_ERROR);
                        return false;
                    }

                    var confirm = $.scojs_confirm({
                        content: "确认要生成"+amount+"张优惠劵吗？",
                        action:function(){
                            $("#submit_button").val("生成中...");
                            $("#submit_button").attr("disabled",true);
                            $("#submit_form").submit();
                        }
                    });
                    confirm.show();
                }
                else{
                    $.scojs_message('请填写数量！', $.scojs_message.TYPE_ERROR);
                }
            });

        });
    </script>
</@override>
<@extends name="../layout.ftl"/>